package com.im.service.conversation.controller;

import com.im.common.model.RestResponse;
import com.im.common.model.SyncReq;
import com.im.service.conversation.model.DeleteConversationReq;
import com.im.service.conversation.model.UpdateConversationReq;
import com.im.service.conversation.service.ConversationServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/conversation")
@Api(tags = "会话相关接口")
public class ConversationController {

    @Autowired
    ConversationServiceImpl conversationService;

    @RequestMapping(value = "/deleteConversation", method = RequestMethod.POST)
    @ApiOperation(value = "删除会话", notes = "根据会话 ID 删除会话")
    public RestResponse deleteConversation(@RequestBody @Validated DeleteConversationReq req, Integer appId) {
        req.setAppId(appId);
        conversationService.deleteConversation(req);
        return RestResponse.success();
    }

    @RequestMapping(value = "/updateConversation", method = RequestMethod.POST)
    @ApiOperation(value = "更新会话", notes = "根据会话 ID 更新会话")
    public RestResponse updateConversation(@RequestBody @Validated UpdateConversationReq req, Integer appId) {
        req.setAppId(appId);
        conversationService.updateConversation(req);
        return RestResponse.success();
    }

    @RequestMapping(value = "/syncConversationList", method = RequestMethod.POST)
    @ApiOperation(value = "同步会话列表", notes = "同步会话列表")
    public RestResponse syncFriendShipList(@RequestBody @Validated SyncReq req, Integer appId) {
        req.setAppId(appId);
        return RestResponse.success(conversationService.syncConversationSet(req));
    }

}
